package com.example.lotterysystem.dao.mapper;

import com.example.lotterysystem.dao.dataobject.ActivityDO;
import com.example.lotterysystem.service.enums.ActivityStatusEnum;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ActivityMapper {

    @Insert("INSERT INTO activity (create_id, activity_name, description, status) " +
            "VALUES (#{createId}, #{activityDO.activityName}, #{activityDO.description}, #{activityDO.status})")
    @Options(useGeneratedKeys = true, keyProperty = "activityDO.id", keyColumn = "id")
    int create(@Param("createId") Integer createId, @Param("activityDO") ActivityDO activityDO);

    @Select("select count(1) from activity")
    int count();

    @Select("select * from activity where create_id = #{createId} order by id desc limit #{offset}, #{pageSize}")
    List<ActivityDO> selectActivityByPage(@Param("createId") Integer createId,
                                          @Param("offset") Integer offset,
                                          @Param("pageSize") Integer pageSize);

    @Select("select * from activity where id = #{id}")
    ActivityDO selectActivityById(@Param("id") Long id);

    @Update("update activity set status = #{status} where id = #{id}")
    void updateStatus(@Param("id") Long id, @Param("status") String status);
}
